<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增用户')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body>
<div class="main-content">
    <form id="form-task-add" class="form-horizontal">
        <h4 class="form-header h4">基本信息</h4>
        <div class="row">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">任务标题：</label>
                        <div class="col-sm-8">
                            <select class="form-control" id="task" name="taskId" onchange="deptChange()">
                                <option value="default">选择任务</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">申请人：</label>
                        <div class="col-sm-8">
                            <select class="form-control" id="crew" name="userId">
                            </select>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">延期至：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            <input id="taskEndTime" type="datetime-local" class="form-control" step="1"
                                   name="taskEndTimeStr">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">申请原因：</label>
                    <div class="col-xs-10">
                        <textarea name="postponeDesc" maxlength="500" class="form-control" rows="3"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭
        </button>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script>
    var prefix = ctx + "hcy/task/postpone";

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-task-add").serializeArray();
            $.operate.saveTab(prefix + "/add", data);
        }
    }

    $(function () {
        $.post(prefix + "/taskList", {}, function (data) {
            if (data != "") {
                var dataArr = eval(data);
                for (var i in dataArr) {
                    $("#task").append("<option value='" + dataArr[i].taskId + "'>" + dataArr[i].taskTitle + "</option>");
                }
            }
        });
    });

    function deptChange() {
        $("#task option[value='default']").remove();
        var taskId = $("#task").val();
        $("#crew").empty();
        $.post(prefix + "/crewOfTask", {"taskId": taskId}, function (data) {
            if (data != "") {
                $("#crew").append("<option value='" + data.crewId + "'>" + data.crewName + "</option>");
            }
        });
    }
</script>
</body>
</html>